home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifDesktopPaneUI.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  162 lines

  1. /*
  2.  * @(#)MotifDesktopPaneUI.java    1.13 98/02/06
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import com.sun.java.swing.*;
  24. import java.awt.Rectangle;
  25. import java.awt.Dimension;
  26. import java.awt.Insets;
  27. import java.awt.Color;
  28. import java.awt.Graphics;
  29. import com.sun.java.swing.plaf.*;
  30. import java.io.Serializable;
  31.  
  32. /**
  33.  * <p>
  34.  * Warning: serialized objects of this class will not be compatible with
  35.  * future swing releases.  The current serialization support is appropriate
  36.  * for short term storage or RMI between Swing1.0 applications.  It will
  37.  * not be possible to load serialized Swing1.0 objects with future releases
  38.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  39.  * baseline for the serialized form of Swing objects.
  40.  *
  41.  * @version 1.13 02/06/98
  42.  * @author David Kloba
  43.  */
  44. public class MotifDesktopPaneUI extends com.sun.java.swing.plaf.basic.BasicDesktopPaneUI
  45. {
  46.  
  47. /// DesktopPaneUI methods
  48.     public static ComponentUI createUI(JComponent d)    {
  49.         return new MotifDesktopPaneUI();
  50.     }
  51.  
  52.     public MotifDesktopPaneUI() {
  53.     }
  54.  
  55.     protected void installDesktopManager() {
  56.     if(desktop.getDesktopManager() == null) {
  57.         desktopManager = new MotifDesktopManager();
  58.         desktop.setDesktopManager(desktopManager);
  59.     }
  60.     }
  61.  
  62.     public Insets getInsets(JComponent c) {return new Insets(0,0,0,0);}
  63.  
  64. ////////////////////////////////////////////////////////////////////////////////////
  65. ///  DragPane class
  66. ////////////////////////////////////////////////////////////////////////////////////
  67.     private class DragPane extends JComponent {
  68.     public void paint(Graphics g) {
  69.         g.setColor(Color.darkGray);
  70.         g.drawRect(0, 0, getWidth()-1, getHeight()-1);
  71.     }
  72.     };
  73.  
  74. ////////////////////////////////////////////////////////////////////////////////////
  75. ///  MotifDesktopManager class
  76. ////////////////////////////////////////////////////////////////////////////////////
  77.     private class MotifDesktopManager extends DefaultDesktopManager implements Serializable {
  78.         JComponent dragPane;
  79.         boolean usingDragPane;
  80.  
  81.     // PENDING(klobad) this should be optimized
  82.     public void setBoundsForFrame(JComponent f, int newX, int newY, 
  83.             int newWidth, int newHeight) {
  84.     if(!usingDragPane) {
  85.             boolean didResize;
  86.             didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
  87.         Rectangle r = f.getBounds();
  88.         f.setBounds(newX, newY, newWidth, newHeight);        
  89.         SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
  90.         f.getParent().repaint(r.x, r.y, r.width, r.height);
  91.         if(didResize) {
  92.             f.validate();
  93.           }
  94.     } else {
  95.         Rectangle r = dragPane.getBounds();
  96.         dragPane.setBounds(newX, newY, newWidth, newHeight);        
  97.         SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
  98.         dragPane.getParent().repaint(r.x, r.y, r.width, r.height);
  99.     }
  100.     }
  101.  
  102.     public void beginDraggingFrame(JComponent f) {    
  103.     usingDragPane = false;
  104.     if(f.getParent() instanceof JLayeredPane) {
  105.         if(dragPane == null)
  106.         dragPane = new DragPane();
  107.         JLayeredPane p = (JLayeredPane)f.getParent();
  108.         p.setLayer(dragPane, Integer.MAX_VALUE);
  109.         dragPane.setBounds(f.getX(), f.getY(), f.getWidth(), f.getHeight());
  110.         p.add(dragPane);
  111.         usingDragPane = true;
  112.     }
  113.     }
  114.  
  115.     public void dragFrame(JComponent f, int newX, int newY) {
  116.     setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
  117.     }
  118.  
  119.     public void endDraggingFrame(JComponent f) {
  120.     if(usingDragPane) {
  121.         JLayeredPane p = (JLayeredPane)f.getParent();
  122.         p.remove(dragPane);
  123.         usingDragPane = false;
  124.             setBoundsForFrame(f, dragPane.getX(), dragPane.getY(), 
  125.                 dragPane.getWidth(), dragPane.getHeight());
  126.     }
  127.     }
  128.  
  129.     public void beginResizingFrame(JComponent f, int direction) {
  130.     usingDragPane = false;
  131.     if(f.getParent() instanceof JLayeredPane) {
  132.         if(dragPane == null)
  133.         dragPane = new DragPane();
  134.         JLayeredPane p = (JLayeredPane)f.getParent();
  135.         p.setLayer(dragPane, Integer.MAX_VALUE);
  136.         dragPane.setBounds(f.getX(), f.getY(), 
  137.                 f.getWidth(), f.getHeight());
  138.         p.add(dragPane);
  139.         usingDragPane = true;
  140.     }
  141.     }
  142.  
  143.     public void resizeFrame(JComponent f, int newX, int newY, 
  144.                 int newWidth, int newHeight) {
  145.     setBoundsForFrame(f, newX, newY, newWidth, newHeight);
  146.     }
  147.  
  148.     public void endResizingFrame(JComponent f) {
  149.     if(usingDragPane) {
  150.         JLayeredPane p = (JLayeredPane)f.getParent();
  151.         p.remove(dragPane);
  152.         usingDragPane = false;
  153.             setBoundsForFrame(f, dragPane.getX(), dragPane.getY(), 
  154.                 dragPane.getWidth(), dragPane.getHeight());
  155.     }
  156.     }
  157.  
  158.     }; /// END of MotifDesktopManager
  159.  
  160. }
  161.  
  162.